home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / misc / LEDA_gene.lha / LEDA-3.1c-generic / incl / LEDA / point.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-10  |  2.7 KB  |  131 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  3.1c
  4. +
  5. +
  6. +  point.h
  7. +
  8. +
  9. +  Copyright (c) 1994  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15. #ifndef LEDA_POINT_H
  16. #define LEDA_POINT_H
  17.  
  18. #include <LEDA/list.h>
  19. #include <LEDA/vector.h>
  20.  
  21. class point;
  22. class segment;
  23.  
  24. //------------------------------------------------------------------------------
  25. // points
  26. //------------------------------------------------------------------------------
  27.  
  28. class point_rep  : public handle_rep {
  29.  
  30. friend class point;
  31. friend class segment;
  32. friend class line;
  33. friend class circle;
  34.    
  35.    double x;
  36.    double y;
  37.  
  38. public:
  39.     
  40.    point_rep();     
  41.    point_rep(double a, double b);
  42.  
  43.   ~point_rep() {}
  44.    
  45.    
  46.    LEDA_MEMORY(point_rep)
  47.    
  48. };
  49.  
  50.  
  51. class point  : public handle_base 
  52. {
  53.  
  54. friend class segment;
  55. friend class line;
  56. friend class circle;
  57.  
  58.  
  59. point_rep* ptr() const { return (point_rep*)PTR; }
  60.  
  61. public:
  62.  
  63.  point();
  64.  point(double, double);
  65.  point(vector);
  66.  point(const point& p) : handle_base(p) {}
  67. ~point()                  { clear(); }
  68.  
  69. point& operator=(const point& p) { handle_base::operator=(p); return *this; }
  70.  
  71.  
  72. operator vector()         { return vector(ptr()->x,ptr()->y); }
  73.  
  74. double  xcoord()  const   { return ptr()->x; }
  75. double  ycoord()  const   { return ptr()->y; }
  76.  
  77. double  angle(const point&, const point&) const;
  78.  
  79. double  distance(const point&) const;
  80. double  distance() const;
  81.  
  82. point   translate(double,double) const;
  83. point   translate(const vector&) const;
  84.  
  85. point   rotate(const point&,double) const;
  86. point   rotate(double) const;
  87.  
  88.  
  89. point operator+(const vector& v) const { return translate(v); }
  90.  
  91. int operator==(const point&) const;
  92.  
  93. int operator!=(const point& p)  const { return !operator==(p);}
  94.  
  95. friend ostream& operator<<(ostream& out, const point& p) ;
  96. friend istream& operator>>(istream& in, point& p) ;
  97.  
  98. friend int compare(const point& a, const point& b)
  99. { int r = compare(a.xcoord(),b.xcoord());
  100.   return (r!=0) ? r : compare(a.ycoord(),b.ycoord());
  101.  }
  102.  
  103.  
  104. };
  105.  
  106. inline void Print(const point& p, ostream& out) { out << p; } 
  107. inline void Read(point& p,  istream& in)        { in >> p; }
  108.  
  109. LEDA_HANDLE_TYPE(point)
  110.  
  111.  
  112.  
  113. // geometric primitives
  114.  
  115.  
  116. inline bool right_turn(const point& a, const point& b, const point& c)
  117. { return (a.ycoord()-b.ycoord()) * (a.xcoord()-c.xcoord())
  118.           + (b.xcoord()-a.xcoord()) * (a.ycoord()-c.ycoord()) > 0;
  119.  }
  120.  
  121. inline bool left_turn(const point& a, const point& b, const point& c)
  122. { return (a.ycoord()-b.ycoord()) * (a.xcoord()-c.xcoord())
  123.           + (b.xcoord()-a.xcoord()) * (a.ycoord()-c.ycoord()) < 0;
  124.  }
  125.  
  126.  
  127.  
  128. #endif
  129.  
  130.